package com.kk.permission.huawei.actionutil;

import android.accessibilityservice.AccessibilityService;
import android.view.accessibility.AccessibilityNodeInfo;

import com.kk.permission.accessibilityutils.NodeUtil;
import com.kk.permission.huawei.HuaweiTool;

import java.util.HashMap;

public class HuaweiBackgroundProtectUtil {
    private final String STEP1 = "step1";
    private final String STEP2 = "step2";
    private final String STEP3 = "step3";
    private final String STEP4 = "step4";
    private final String STEP5 = "step5";
    private final String STEP6 = "step6";
    private String mAppName = HuaweiTool.getAppName();
    private HashMap<String, String> mStepMap = new HashMap();
    private boolean result = false;

    public boolean backgroundProtect(AccessibilityNodeInfo accessibilityNodeInfo, AccessibilityService accessibilityService) {
        if (this.result) {
            return true;
        }
        if (NodeUtil.pageContains(accessibilityNodeInfo, "受保护应用") || NodeUtil.pageContains(accessibilityNodeInfo, "锁屏清理应用")) {
            if (this.mStepMap.containsKey("step1")) {
                if (!this.mStepMap.containsKey("step2")) {
                    this.mStepMap.put("step2", "1");
                    this.result = true;
                    HuaweiTool.actionBackgroundProtectDone();
                    NodeUtil.back(accessibilityService);
                }
            } else if (NodeUtil.pageContains(accessibilityNodeInfo, this.mAppName)) {
                if (!this.mStepMap.containsKey("step1")) {
                    this.mStepMap.put("step1", "1");
                    NodeUtil.clickByText(accessibilityNodeInfo, this.mAppName);
                }
            } else if (!this.mStepMap.containsKey("step1")) {
                NodeUtil.scrollForward(NodeUtil.getScrollableNode(accessibilityNodeInfo));
            }
        }
        return false;
    }
}
